PROJECTENGRAM

[PS] CACHE MEMORY 1

Tags: #◇Computer Science #◇CSARCH2 #◇Cache Memory #◇Computer Architecture #◇Direct Mapping #◇Fully Associative Mapping #◇Set Associative Mapping #◇LRU Replacement #◇MRU Replacement #◇AMAT


Problem Set: Cache Memory 1

◇Architectural Foundations & Formula Reference

1. Memory Hierarchy & Locality Principles

Cache memory serves as a high-speed buffer positioned between the processor core and main memory (DRAM\text{DRAM}). Its effectiveness relies upon two fundamental properties of program execution:

  • Temporal Locality: If a memory location is referenced, it is highly likely to be referenced again in the near future (e.g., loop variables, subroutine instructions).
  • Spatial Locality: If a memory location is referenced, nearby memory locations are likely to be referenced soon (e.g., sequential instruction execution, array traversals).
『』
TEXT
   ┌─────────────────────────────────────────────────────────────┐
   │                        Processor Core                       │
   └──────────────────────────────┬──────────────────────────────┘
                                  │ (Address Bus)
                                  ▼
   ┌─────────────────────────────────────────────────────────────┐
   │                         Cache Memory                        │
   │  ┌───────────────┬─────────────────────────┬─────────────┐  │
   │  │ Valid Bit (V) │ Tag Directory (TAG)     │ Data Block  │  │
   │  └───────────────┴─────────────────────────┴─────────────┘  │
   └──────────────────────────────┬──────────────────────────────┘
                                  │ (Cache Miss Refill)
                                  ▼
   ┌─────────────────────────────────────────────────────────────┐
   │                         Main Memory                         │
   └─────────────────────────────────────────────────────────────┘

2. Address Bit-Field Partitioning Derivations

For a memory system with word-addressable or byte-addressable main memory:

  • Let MM be the total number of addressable units (words or bytes) in main memory   ⟹  Address Bits A=log⁡2(M)\implies \text{Address Bits } A = \log_2(M).
  • Let BB be the block size (in addressable units)   ⟹  Offset Bits w=log⁡2(B)\implies \text{Offset Bits } w = \log_2(B).
  • Let CC be the total number of lines/blocks in the cache.

A. Direct Mapping

Every main memory block maps to exactly one cache line:
Line Index=MM Block Number(modC)\text{Line Index} = \text{MM Block Number} \pmod C
Address Format: [ TAG (t)∣BLOCK INDEX (s)∣WORD/BYTE OFFSET (w) ]\text{Address Format: } [\ \text{TAG } (t) \mid \text{BLOCK INDEX } (s) \mid \text{WORD/BYTE OFFSET } (w)\ ]
Where:

  • Offset Bits w=log⁡2(B)\text{Offset Bits } w = \log_2(B)
  • Block/Line Bits s=log⁡2(C)\text{Block/Line Bits } s = \log_2(C)
  • Tag Bits t=A−(s+w)=log⁡2(Total MM BlocksC)\text{Tag Bits } t = A - (s + w) = \log_2\left(\frac{\text{Total MM Blocks}}{C}\right)

B. Fully Associative Mapping

A main memory block can be placed in any available cache line:
Address Format: [ TAG (t)∣WORD/BYTE OFFSET (w) ]\text{Address Format: } [\ \text{TAG } (t) \mid \text{WORD/BYTE OFFSET } (w)\ ]
Where:

  • Offset Bits w=log⁡2(B)\text{Offset Bits } w = \log_2(B)
  • Tag Bits t=A−w=log⁡2(Total MM Blocks)\text{Tag Bits } t = A - w = \log_2(\text{Total MM Blocks})

C. KK-Way Set Associative Mapping

Cache lines are grouped into SS sets, where each set contains KK lines (C=S×KC = S \times K):
Set Index=MM Block Number(modS)\text{Set Index} = \text{MM Block Number} \pmod S
Address Format: [ TAG (t)∣SET INDEX (d)∣WORD/BYTE OFFSET (w) ]\text{Address Format: } [\ \text{TAG } (t) \mid \text{SET INDEX } (d) \mid \text{WORD/BYTE OFFSET } (w)\ ]
Where:

  • Offset Bits w=log⁡2(B)\text{Offset Bits } w = \log_2(B)
  • Set Bits d=log⁡2(S)=log⁡2(CK)\text{Set Bits } d = \log_2(S) = \log_2\left(\frac{C}{K}\right)
  • Tag Bits t=A−(d+w)=log⁡2(Total MM BlocksS)\text{Tag Bits } t = A - (d + w) = \log_2\left(\frac{\text{Total MM Blocks}}{S}\right)

3. Cache Storage Overhead Derivations

Total physical storage required for an SRAM cache implementation comprises data payload, tag directory, and status flags:
Total Bits per Line=Data Bits+Tag Bits+Valid Bit+Dirty Bit (if Write-Back)\text{Total Bits per Line} = \text{Data Bits} + \text{Tag Bits} + \text{Valid Bit} + \text{Dirty Bit (if Write-Back)}
Total Cache Storage (Bits)=C×(B×Bits per Unit+t+1)\text{Total Cache Storage (Bits)} = C \times \left( B \times \text{Bits per Unit} + t + 1 \right)


4. Memory Performance & Timing Models

  • Hit Ratio (HH): Fraction of memory accesses satisfied by the cache:
    H=NhitsNtotal accessesH = \frac{N_{\text{hits}}}{N_{\text{total accesses}}}
  • Miss Ratio (MM): Fraction of accesses resulting in cache misses:
    M=1−H=NmissesNtotal accessesM = 1 - H = \frac{N_{\text{misses}}}{N_{\text{total accesses}}}
  • Average Memory Access Time (◇AMAT):
    • Non-Load-Through / Sequential Access (Cache is checked first; upon miss, main memory is accessed):
      tmiss=tcache+tmemt_{\text{miss}} = t_{\text{cache}} + t_{\text{mem}}
      AMAT=H⋅tcache+(1−H)⋅(tcache+tmem)=tcache+(1−H)⋅tmem\text{AMAT} = H \cdot t_{\text{cache}} + (1-H) \cdot (t_{\text{cache}} + t_{\text{mem}}) = t_{\text{cache}} + (1-H) \cdot t_{\text{mem}}
    • Load-Through / Simultaneous Access (Main memory delivers word directly to CPU in parallel):
      AMAT=H⋅tcache+(1−H)⋅tmem\text{AMAT} = H \cdot t_{\text{cache}} + (1-H) \cdot t_{\text{mem}}

◇Problem 0a: Sizing & Address Format Analysis

Problem Statement

A cache contains 4 blocks4\text{ blocks}. Main memory contains 16 blocks16\text{ blocks}. Each block contains 2 words2\text{ words}. Each word is 16 bits16\text{ bits}. Assume a word-addressable memory architecture.

『』
TEXT
+--------------------------------------------------------------------+
| Cache Capacity: 4 blocks                                           |
| Main Memory Capacity: 16 blocks                                    |
| Block Size (B): 2 words (32 bits per block)                        |
| Word Width: 16 bits                                                |
+--------------------------------------------------------------------+

Detailed Derivations & Solutions

a. Main Memory Address Width

  • Total words in main memory:
    Nwords=16 blocks×2 words/block=32 wordsN_{\text{words}} = 16\text{ blocks} \times 2\text{ words/block} = 32\text{ words}
  • Total address bits:
    A=log⁡2(32)=5 bitsA = \log_2(32) = 5\text{ bits}

(Note: If byte-addressing with 2 bytes/word were specified, total bytes = 64, requiring A=6 bitsA = 6\text{ bits} with 1 byte-offset bit. In standard word-addressing, A=5 bitsA = 5\text{ bits}.)


b. Direct Mapping Field Partitioning

  • WORD Offset Field (w)=log⁡2(2 words/block)=1 bit\text{WORD Offset Field } (w) = \log_2(2\text{ words/block}) = 1\text{ bit}
  • BLOCK Index Field (s)=log⁡2(4 cache blocks)=2 bits\text{BLOCK Index Field } (s) = \log_2(4\text{ cache blocks}) = 2\text{ bits}
  • TAG Field (t)=5−(2+1)=2 bits\text{TAG Field } (t) = 5 - (2 + 1) = 2\text{ bits}

TAG (2 bits)BLOCK (2 bits)WORD (1 bit)Bits [4:3]Bits [2:1]Bit [0]\begin{array}{|c|c|c|} \hline \textbf{TAG (2 bits)} & \textbf{BLOCK (2 bits)} & \textbf{WORD (1 bit)} \\ \hline \text{Bits [4:3]} & \text{Bits [2:1]} & \text{Bit [0]} \\ \hline \end{array}


c. Fully Associative Mapping Field Partitioning

  • WORD Offset Field (w)=log⁡2(2 words/block)=1 bit\text{WORD Offset Field } (w) = \log_2(2\text{ words/block}) = 1\text{ bit}
  • TAG Field (t)=5−1=4 bits\text{TAG Field } (t) = 5 - 1 = 4\text{ bits}

TAG (4 bits)WORD (1 bit)Bits [4:1]Bit [0]\begin{array}{|c|c|} \hline \textbf{TAG (4 bits)} & \textbf{WORD (1 bit)} \\ \hline \text{Bits [4:1]} & \text{Bit [0]} \\ \hline \end{array}


d. Block Set Associative Mapping Field Partitioning (2 blocks/set)

  • Number of Sets:
    S=4 cache blocks2 blocks/set=2 setsS = \frac{4\text{ cache blocks}}{2\text{ blocks/set}} = 2\text{ sets}
  • WORD Offset Field (w)=log⁡2(2)=1 bit\text{WORD Offset Field } (w) = \log_2(2) = 1\text{ bit}
  • SET Index Field (d)=log⁡2(2 sets)=1 bit\text{SET Index Field } (d) = \log_2(2\text{ sets}) = 1\text{ bit}
  • TAG Field (t)=5−(1+1)=3 bits\text{TAG Field } (t) = 5 - (1 + 1) = 3\text{ bits}

TAG (3 bits)SET (1 bit)WORD (1 bit)Bits [4:2]Bit [1]Bit [0]\begin{array}{|c|c|c|} \hline \textbf{TAG (3 bits)} & \textbf{SET (1 bit)} & \textbf{WORD (1 bit)} \\ \hline \text{Bits [4:2]} & \text{Bit [1]} & \text{Bit [0]} \\ \hline \end{array}


e. Cache Memory Size (Direct-Mapped)

  • Data Capacity:
    Data Bits=4 blocks×2 words/block×16 bits/word=128 bits\text{Data Bits} = 4\text{ blocks} \times 2\text{ words/block} \times 16\text{ bits/word} = 128\text{ bits}
  • Total Physical Cache Size (with 1 Valid Bit + 2 Tag Bits per line):
    Size=4×(32 data+2 tag+1 valid)=4×35=140 bits\text{Size} = 4 \times (32\text{ data} + 2\text{ tag} + 1\text{ valid}) = 4 \times 35 = 140\text{ bits}
    (Data-only: 128 bits128\text{ bits}; Without valid bit: 4×34=136 bits4 \times 34 = 136\text{ bits})

f. Cache Memory Size (Fully Associative)

  • Data Capacity: 128 bits128\text{ bits}
  • Total Physical Cache Size (with 1 Valid Bit + 4 Tag Bits per line):
    Size=4×(32 data+4 tag+1 valid)=4×37=148 bits\text{Size} = 4 \times (32\text{ data} + 4\text{ tag} + 1\text{ valid}) = 4 \times 37 = 148\text{ bits}
    (Data-only: 128 bits128\text{ bits}; Without valid bit: 4×36=144 bits4 \times 36 = 144\text{ bits})

g. Cache Memory Size (2-Way Set Associative)

  • Data Capacity: 128 bits128\text{ bits}
  • Total Physical Cache Size (with 1 Valid Bit + 3 Tag Bits per line):
    Size=4×(32 data+3 tag+1 valid)=4×36=144 bits\text{Size} = 4 \times (32\text{ data} + 3\text{ tag} + 1\text{ valid}) = 4 \times 36 = 144\text{ bits}
    (Data-only: 128 bits128\text{ bits}; Without valid bit: 4×35=140 bits4 \times 35 = 140\text{ bits})

h. Main Memory Size

MM Size=16 blocks×2 words/block×16 bits/word=32 words×16 bits=512 bits(64 bytes)\text{MM Size} = 16\text{ blocks} \times 2\text{ words/block} \times 16\text{ bits/word} = 32\text{ words} \times 16\text{ bits} = 512\text{ bits} \quad (64\text{ bytes})


i. Mapping of Memory Block 9 (Direct Mapping)

Cache Block=MM Block(modTotal Cache Blocks)=9(mod4)=1\text{Cache Block} = \text{MM Block} \pmod{\text{Total Cache Blocks}} = 9 \pmod 4 = 1
Memory Block 9 maps to Cache Block 1\mathbf{\text{Memory Block 9 maps to Cache Block 1}}


j. Mapping of Memory Address 9 (Direct Mapping)

  • Memory Address 910=0100129_{10} = 01001_2
  • Main Memory Block Number:
    MM Block=⌊AddressBlock Size⌋=⌊92⌋=4\text{MM Block} = \left\lfloor \frac{\text{Address}}{\text{Block Size}} \right\rfloor = \left\lfloor \frac{9}{2} \right\rfloor = 4
  • Target Cache Block:
    Cache Block=4(mod4)=0\text{Cache Block} = 4 \pmod 4 = 0
  • Binary Verification:
    • TAG=012=1\text{TAG} = 01_2 = 1
    • BLOCK=002=0\text{BLOCK} = 00_2 = 0
    • WORD=12=1\text{WORD} = 1_2 = 1
      Memory Address 9 maps to Cache Block 0\mathbf{\text{Memory Address 9 maps to Cache Block 0}}

k. Mapping of Memory Block 9 (Set Associative, 2 sets)

Cache Set=MM Block(modTotal Sets)=9(mod2)=1\text{Cache Set} = \text{MM Block} \pmod{\text{Total Sets}} = 9 \pmod 2 = 1
Memory Block 9 maps to Cache Set 1\mathbf{\text{Memory Block 9 maps to Cache Set 1}}


l. Mapping of Memory Address 9 (Set Associative, 2 sets)

  • Memory Address 910=010012  ⟹  MM Block=⌊9/2⌋=49_{10} = 01001_2 \implies \text{MM Block} = \lfloor 9/2 \rfloor = 4
  • Target Cache Set:
    Cache Set=4(mod2)=0\text{Cache Set} = 4 \pmod 2 = 0
  • Binary Verification:
    • TAG=0102=2\text{TAG} = 010_2 = 2
    • SET=02=0\text{SET} = 0_2 = 0
    • WORD=12=1\text{WORD} = 1_2 = 1
      Memory Address 9 maps to Cache Set 0\mathbf{\text{Memory Address 9 maps to Cache Set 0}}

◇Problem 0b: Access Traces & Replacement Algorithms

Problem Statement

Using the cache parameters from Problem 0a (4 cache blocks4\text{ cache blocks}, 16 MM blocks16\text{ MM blocks}, 2 words/block2\text{ words/block}, 16 bits/word16\text{ bits/word}, tcache=1 nst_{\text{cache}} = 1\text{ ns}, tmem=10 nst_{\text{mem}} = 10\text{ ns}), evaluate the following main memory block reference sequence:
Sequence: 1,7,5,0,2,1,3,6,1,3,4,7,9(N=13 accesses)\text{Sequence: } 1, 7, 5, 0, 2, 1, 3, 6, 1, 3, 4, 7, 9 \quad (N = 13\text{ accesses})

Assuming a non-load-through read policy:

  • Hit Penalty: thit=tcache=1 nst_{\text{hit}} = t_{\text{cache}} = 1\text{ ns}
  • Miss Penalty: tmiss=tcache+tmem=1 ns+10 ns=11 nst_{\text{miss}} = t_{\text{cache}} + t_{\text{mem}} = 1\text{ ns} + 10\text{ ns} = 11\text{ ns}

Step-by-Step Access Traces

1. Direct-Mapped Cache Trace (n,on, o)

Line mapping rule: Line=Block(mod4)\text{Line} = \text{Block} \pmod 4.

StepBlock RefTarget LineInitial Line ContentHit/MissEvicted BlockCache State [L0,L1,L2,L3][L_0, L_1, L_2, L_3]Access Time
11Line 1EmptyMISSNone[−,1,−,−][-, 1, -, -]11 ns11\text{ ns}
27Line 3EmptyMISSNone[−,1,−,7][-, 1, -, 7]11 ns11\text{ ns}
35Line 11MISS1[−,5,−,7][-, 5, -, 7]11 ns11\text{ ns}
40Line 0EmptyMISSNone[0,5,−,7][0, 5, -, 7]11 ns11\text{ ns}
52Line 2EmptyMISSNone[0,5,2,7][0, 5, 2, 7]11 ns11\text{ ns}
61Line 15MISS5[0,1,2,7][0, 1, 2, 7]11 ns11\text{ ns}
73Line 37MISS7[0,1,2,3][0, 1, 2, 3]11 ns11\text{ ns}
86Line 22MISS2[0,1,6,3][0, 1, 6, 3]11 ns11\text{ ns}
91Line 11HITNone[0,1,6,3][0, 1, 6, 3]1 ns1\text{ ns}
103Line 33HITNone[0,1,6,3][0, 1, 6, 3]1 ns1\text{ ns}
114Line 00MISS0[4,1,6,3][4, 1, 6, 3]11 ns11\text{ ns}
127Line 33MISS3[4,1,6,7][4, 1, 6, 7]11 ns11\text{ ns}
139Line 11MISS1[4,9,6,7][4, 9, 6, 7]11 ns11\text{ ns}
  • Performance Metrics:
    • Hits: 22, Misses: 1111
    • Hit Ratio: H=213≈15.38%H = \frac{2}{13} \approx 15.38\%
    • Miss Ratio: M=1113≈84.62%M = \frac{11}{13} \approx 84.62\%
    • Final Cache Contents: Line 0 = 4, Line 1 = 9, Line 2 = 6, Line 3 = 7
    • Total Access Time: Ttotal=(2×1 ns)+(11×11 ns)=2+121=123 nsT_{\text{total}} = (2 \times 1\text{ ns}) + (11 \times 11\text{ ns}) = 2 + 121 = 123\text{ ns}
    • Average Access Time: AMAT=123 ns13≈9.4615 ns\text{AMAT} = \frac{123\text{ ns}}{13} \approx \mathbf{9.4615\text{ ns}}

2. Fully Associative + LRU Trace (p,qp, q)

Capacity = 4 blocks. LRU order: [MRU→⋯→LRU]\text{[MRU} \rightarrow \dots \rightarrow \text{LRU]}.

StepBlock RefHit/MissReplacement / Insertion ActionCache State (MRU →\rightarrow LRU)Access Time
11MISSInsert 1[1][1]11 ns11\text{ ns}
27MISSInsert 7[7,1][7, 1]11 ns11\text{ ns}
35MISSInsert 5[5,7,1][5, 7, 1]11 ns11\text{ ns}
40MISSInsert 0 (Full)[0,5,7,1][0, 5, 7, 1]11 ns11\text{ ns}
52MISSEvict LRU (1), Insert 2[2,0,5,7][2, 0, 5, 7]11 ns11\text{ ns}
61MISSEvict LRU (7), Insert 1[1,2,0,5][1, 2, 0, 5]11 ns11\text{ ns}
73MISSEvict LRU (5), Insert 3[3,1,2,0][3, 1, 2, 0]11 ns11\text{ ns}
86MISSEvict LRU (0), Insert 6[6,3,1,2][6, 3, 1, 2]11 ns11\text{ ns}
91HITPromote 1 to MRU[1,6,3,2][1, 6, 3, 2]1 ns1\text{ ns}
103HITPromote 3 to MRU[3,1,6,2][3, 1, 6, 2]1 ns1\text{ ns}
114MISSEvict LRU (2), Insert 4[4,3,1,6][4, 3, 1, 6]11 ns11\text{ ns}
127MISSEvict LRU (6), Insert 7[7,4,3,1][7, 4, 3, 1]11 ns11\text{ ns}
139MISSEvict LRU (1), Insert 9[9,7,4,3][9, 7, 4, 3]11 ns11\text{ ns}
  • Performance Metrics:
    • Hits: 22, Misses: 1111
    • Final Cache Contents: {9,7,4,3}\{9, 7, 4, 3\}
    • Total Access Time: 123 ns123\text{ ns}
    • Average Access Time: AMAT=123 ns13≈9.4615 ns\text{AMAT} = \frac{123\text{ ns}}{13} \approx \mathbf{9.4615\text{ ns}}

3. Fully Associative + MRU Trace (r,sr, s)

Capacity = 4 blocks. On miss when full, evict the Most Recently Used block (MRU\text{MRU}).

StepBlock RefHit/MissCurrent MRUAction / Evicted BlockCache ContentsNew MRUAccess Time
11MISSNoneInsert 1{1}\{1\}111 ns11\text{ ns}
27MISS1Insert 7{1,7}\{1, 7\}711 ns11\text{ ns}
35MISS7Insert 5{1,7,5}\{1, 7, 5\}511 ns11\text{ ns}
40MISS5Insert 0 (Full){1,7,5,0}\{1, 7, 5, 0\}011 ns11\text{ ns}
52MISS0Evict MRU (0), Insert 2{1,7,5,2}\{1, 7, 5, 2\}211 ns11\text{ ns}
61HIT2Update MRU to 1{1,7,5,2}\{1, 7, 5, 2\}11 ns1\text{ ns}
73MISS1Evict MRU (1), Insert 3{3,7,5,2}\{3, 7, 5, 2\}311 ns11\text{ ns}
86MISS3Evict MRU (3), Insert 6{6,7,5,2}\{6, 7, 5, 2\}611 ns11\text{ ns}
91MISS6Evict MRU (6), Insert 1{1,7,5,2}\{1, 7, 5, 2\}111 ns11\text{ ns}
103MISS1Evict MRU (1), Insert 3{3,7,5,2}\{3, 7, 5, 2\}311 ns11\text{ ns}
114MISS3Evict MRU (3), Insert 4{4,7,5,2}\{4, 7, 5, 2\}411 ns11\text{ ns}
127HIT4Update MRU to 7{4,7,5,2}\{4, 7, 5, 2\}71 ns1\text{ ns}
139MISS7Evict MRU (7), Insert 9{4,9,5,2}\{4, 9, 5, 2\}911 ns11\text{ ns}
  • Performance Metrics:
    • Hits: 22 (Access 6: Block 1, Access 12: Block 7)
    • Misses: 1111
    • Final Cache Contents: {4,9,5,2}\{4, 9, 5, 2\}
    • Total Access Time: 123 ns123\text{ ns}
    • Average Access Time: AMAT=123 ns13≈9.4615 ns\text{AMAT} = \frac{123\text{ ns}}{13} \approx \mathbf{9.4615\text{ ns}}

4. 2-Way Set Associative + LRU Trace (t,ut, u)

Number of Sets = 2 (Set 0 for even blocks, Set 1 for odd blocks). Set Capacity = 2 blocks.

StepBlock RefTarget SetSet Hit/MissEvicted BlockSet 0 (MRU →\rightarrow LRU)Set 1 (MRU →\rightarrow LRU)Access Time
11Set 1MISSNone[][][1][1]11 ns11\text{ ns}
27Set 1MISSNone[][][7,1][7, 1]11 ns11\text{ ns}
35Set 1MISS1 (LRU)[][][5,7][5, 7]11 ns11\text{ ns}
40Set 0MISSNone[0][0][5,7][5, 7]11 ns11\text{ ns}
52Set 0MISSNone[2,0][2, 0][5,7][5, 7]11 ns11\text{ ns}
61Set 1MISS7 (LRU)[2,0][2, 0][1,5][1, 5]11 ns11\text{ ns}
73Set 1MISS5 (LRU)[2,0][2, 0][3,1][3, 1]11 ns11\text{ ns}
86Set 0MISS0 (LRU)[6,2][6, 2][3,1][3, 1]11 ns11\text{ ns}
91Set 1HITNone[6,2][6, 2][1,3][1, 3]1 ns1\text{ ns}
103Set 1HITNone[6,2][6, 2][3,1][3, 1]1 ns1\text{ ns}
114Set 0MISS2 (LRU)[4,6][4, 6][3,1][3, 1]11 ns11\text{ ns}
127Set 1MISS1 (LRU)[4,6][4, 6][7,3][7, 3]11 ns11\text{ ns}
139Set 1MISS3 (LRU)[4,6][4, 6][9,7][9, 7]11 ns11\text{ ns}
  • Performance Metrics:
    • Hits: 22 (Access 9: Block 1, Access 10: Block 3)
    • Misses: 1111
    • Final Cache Contents: Set 0 = {4,6}\{4, 6\}, Set 1 = {9,7}\{9, 7\}
    • Total Access Time: 123 ns123\text{ ns}
    • Average Access Time: AMAT=123 ns13≈9.4615 ns\text{AMAT} = \frac{123\text{ ns}}{13} \approx \mathbf{9.4615\text{ ns}}

5. 2-Way Set Associative + MRU Trace (v,wv, w)

Number of Sets = 2. On miss in a full set, evict the set's Most Recently Used block.

StepBlock RefTarget SetSet Hit/MissEvicted BlockSet 0 [MRU]Set 1 [MRU]Access Time
11Set 1MISSNone[][]{1} [1]\{1\} \ [1]11 ns11\text{ ns}
27Set 1MISSNone[][]{1,7} [7]\{1, 7\} \ [7]11 ns11\text{ ns}
35Set 1MISS7 (MRU)[][]{1,5} [5]\{1, 5\} \ [5]11 ns11\text{ ns}
40Set 0MISSNone{0} [0]\{0\} \ [0]{1,5} [5]\{1, 5\} \ [5]11 ns11\text{ ns}
52Set 0MISSNone{0,2} [2]\{0, 2\} \ [2]{1,5} [5]\{1, 5\} \ [5]11 ns11\text{ ns}
61Set 1HITNone{0,2} [2]\{0, 2\} \ [2]{1,5} [1]\{1, 5\} \ [1]1 ns1\text{ ns}
73Set 1MISS1 (MRU){0,2} [2]\{0, 2\} \ [2]{3,5} [3]\{3, 5\} \ [3]11 ns11\text{ ns}
86Set 0MISS2 (MRU){0,6} [6]\{0, 6\} \ [6]{3,5} [3]\{3, 5\} \ [3]11 ns11\text{ ns}
91Set 1MISS3 (MRU){0,6} [6]\{0, 6\} \ [6]{1,5} [1]\{1, 5\} \ [1]11 ns11\text{ ns}
103Set 1MISS1 (MRU){0,6} [6]\{0, 6\} \ [6]{3,5} [3]\{3, 5\} \ [3]11 ns11\text{ ns}
114Set 0MISS6 (MRU){0,4} [4]\{0, 4\} \ [4]{3,5} [3]\{3, 5\} \ [3]11 ns11\text{ ns}
127Set 1MISS3 (MRU){0,4} [4]\{0, 4\} \ [4]{7,5} [7]\{7, 5\} \ [7]11 ns11\text{ ns}
139Set 1MISS7 (MRU){0,4} [4]\{0, 4\} \ [4]{9,5} [9]\{9, 5\} \ [9]11 ns11\text{ ns}
  • Performance Metrics:
    • Hits: 11 (Access 6: Block 1)
    • Misses: 1212
    • Hit Ratio: H=113≈7.69%H = \frac{1}{13} \approx 7.69\%
    • Miss Ratio: M=1213≈92.31%M = \frac{12}{13} \approx 92.31\%
    • Final Cache Contents: Set 0 = {0,4}\{0, 4\}, Set 1 = {9,5}\{9, 5\}
    • Total Access Time: Ttotal=(1×1 ns)+(12×11 ns)=1+132=133 nsT_{\text{total}} = (1 \times 1\text{ ns}) + (12 \times 11\text{ ns}) = 1 + 132 = 133\text{ ns}
    • Average Access Time: AMAT=133 ns13≈10.2308 ns\text{AMAT} = \frac{133\text{ ns}}{13} \approx \mathbf{10.2308\text{ ns}}

Comparative Summary Table for Problem 0b

Cache ArchitectureHitsMissesHit Ratio (HH)Miss Ratio (MM)Final Cache BlocksAMAT (ns)
Direct-Mapped21115.38%15.38\%84.62%84.62\%L0:4,L1:9,L2:6,L3:7L_0:4, L_1:9, L_2:6, L_3:79.46159.4615
Fully Associative (LRU)21115.38%15.38\%84.62%84.62\%{9,7,4,3}\{9, 7, 4, 3\}9.46159.4615
Fully Associative (MRU)21115.38%15.38\%84.62%84.62\%{4,9,5,2}\{4, 9, 5, 2\}9.46159.4615
2-Way Set Assoc (LRU)21115.38%15.38\%84.62%84.62\%S0:{4,6},S1:{9,7}S_0:\{4, 6\}, S_1:\{9, 7\}9.46159.4615
2-Way Set Assoc (MRU)1127.69%7.69\%92.31%92.31\%S0:{0,4},S1:{9,5}S_0:\{0, 4\}, S_1:\{9, 5\}10.230810.2308

◇Problem 1: Sizing a 64-Block Direct-Mapped Cache

Problem Statement

A direct-mapped cache consists of 64 blocks64\text{ blocks}. Main memory contains 4096 blocks4096\text{ blocks}, each consisting of 128 words128\text{ words}. Each word is 16 bits16\text{ bits}.

『』
TEXT
+--------------------------------------------------------------------+
| Cache Organization: Direct-Mapped (64 lines)                       |
| Main Memory Size: 4096 blocks                                      |
| Block Size: 128 words per block (2048 data bits)                   |
| Word Width: 16 bits                                                |
+--------------------------------------------------------------------+

Step-by-Step Solutions

a. Main Memory Address Width

  • Total words in main memory:
    Nwords=4096 blocks×128 words/block=212×27=219 words=524,288 wordsN_{\text{words}} = 4096\text{ blocks} \times 128\text{ words/block} = 2^{12} \times 2^7 = 2^{19}\text{ words} = 524,288\text{ words}
  • Total address bits:
    A=log⁡2(524,288)=19 bitsA = \log_2(524,288) = \mathbf{19\text{ bits}}

b. TAG, BLOCK, and WORD Fields

  • WORD Offset (w)=log⁡2(128 words/block)=7 bits\text{WORD Offset } (w) = \log_2(128\text{ words/block}) = 7\text{ bits}
  • BLOCK Index (s)=log⁡2(64 cache blocks)=6 bits\text{BLOCK Index } (s) = \log_2(64\text{ cache blocks}) = 6\text{ bits}
  • TAG Field (t)=19−(6+7)=6 bits\text{TAG Field } (t) = 19 - (6 + 7) = \mathbf{6\text{ bits}}

TAGBLOCK INDEXWORD OFFSET6 bits (Bits [18:13])6 bits (Bits [12:7])7 bits (Bits [6:0])\begin{array}{|c|c|c|} \hline \textbf{TAG} & \textbf{BLOCK INDEX} & \textbf{WORD OFFSET} \\ \hline \text{6 bits (Bits [18:13])} & \text{6 bits (Bits [12:7])} & \text{7 bits (Bits [6:0])} \\ \hline \end{array}


c. Total Cache Size (including Tag and Valid bits)

  • Bits per cache line:
    Data Bits=128 words×16 bits/word=2048 bits\text{Data Bits} = 128\text{ words} \times 16\text{ bits/word} = 2048\text{ bits}
    Tag Bits=6 bits\text{Tag Bits} = 6\text{ bits}
    Valid Bit=1 bit\text{Valid Bit} = 1\text{ bit}
    Bits per Line=2048+6+1=2055 bits\text{Bits per Line} = 2048 + 6 + 1 = 2055\text{ bits}
  • Total cache memory size:
    Total Bits=64 lines×2055 bits/line=131,520 bits(16,440 bytes≈16.05 KiB)\text{Total Bits} = 64\text{ lines} \times 2055\text{ bits/line} = \mathbf{131,520\text{ bits}} \quad (16,440\text{ bytes} \approx 16.05\text{ KiB})
    (Pure Data Storage = 64×2048=131,072 bits=16 KiB64 \times 2048 = 131,072\text{ bits} = 16\text{ KiB})

d. Total Main Memory Size

MM Size=524,288 words×16 bits/word=8,388,608 bits(1,048,576 bytes=1 MiB)\text{MM Size} = 524,288\text{ words} \times 16\text{ bits/word} = \mathbf{8,388,608\text{ bits}} \quad (1,048,576\text{ bytes} = 1\text{ MiB})


e. Mapping of Memory Block 1000

Cache Block Index=MM Block Number(modTotal Cache Blocks)=1000(mod64)=40\text{Cache Block Index} = \text{MM Block Number} \pmod{\text{Total Cache Blocks}} = 1000 \pmod{64} = \mathbf{40}
Memory Block 1000 maps to Cache Block 40\mathbf{\text{Memory Block 1000 maps to Cache Block 40}}


f. Mapping of Memory Address 1000

  • Memory Address 100010=000000000111110100021000_{10} = 0000000001111101000_2
  • Block Number:
    MM Block=⌊1000128⌋=7\text{MM Block} = \left\lfloor \frac{1000}{128} \right\rfloor = 7
  • Cache Block:
    Cache Block=7(mod64)=7\text{Cache Block} = 7 \pmod{64} = \mathbf{7}
  • Bit verification:
    • Word Offset=1000(mod128)=104=11010002\text{Word Offset} = 1000 \pmod{128} = 104 = 1101000_2 (Bits [6:0])
    • Block Index=0001112=7\text{Block Index} = 000111_2 = 7 (Bits [12:7])
    • Tag=0000002=0\text{Tag} = 000000_2 = 0 (Bits [18:13])
      Memory Address 1000 maps to Cache Block 7\mathbf{\text{Memory Address 1000 maps to Cache Block 7}}

◇Problem 2: Sizing a 64-Block Fully Associative Cache

Problem Statement

An associative cache consists of 64 blocks64\text{ blocks}. Main memory contains 4096 blocks4096\text{ blocks}, each of 128 words128\text{ words}, with 16 bits16\text{ bits} per word.


Step-by-Step Solutions

a. Main Memory Address Width

A=log⁡2(4096×128)=log⁡2(219)=19 bitsA = \log_2(4096 \times 128) = \log_2(2^{19}) = \mathbf{19\text{ bits}}


b. TAG and WORD Fields

  • WORD Offset (w)=log⁡2(128)=7 bits\text{WORD Offset } (w) = \log_2(128) = 7\text{ bits}
  • TAG Field (t)=19−7=12 bits(log⁡2(4096)=12 bits)\text{TAG Field } (t) = 19 - 7 = \mathbf{12\text{ bits}} \quad (\log_2(4096) = 12\text{ bits})

TAG (12 bits)WORD OFFSET (7 bits)Bits [18:7]Bits [6:0]\begin{array}{|c|c|} \hline \textbf{TAG (12 bits)} & \textbf{WORD OFFSET (7 bits)} \\ \hline \text{Bits [18:7]} & \text{Bits [6:0]} \\ \hline \end{array}


c. Mapping of Memory Block 1000

In a fully associative cache, there is no fixed line assignment. Memory Block 1000 can be placed in ANY of the 64 cache blocks (Blocks 0 through 63), subject to the cache replacement policy.


d. Mapping of Memory Address 1000

Memory Address 1000 belongs to MM Block 7 (⌊1000/128⌋=7\lfloor 1000/128 \rfloor = 7). It can be placed in ANY of the 64 cache blocks (Blocks 0 through 63).


e. Total Cache Size (including Tag and Valid bits)

  • Bits per cache line:
    Line Bits=2048 data+12 tag+1 valid=2061 bits\text{Line Bits} = 2048\text{ data} + 12\text{ tag} + 1\text{ valid} = 2061\text{ bits}
  • Total cache memory size:
    Total Bits=64×2061=131,904 bits(16,488 bytes≈16.10 KiB)\text{Total Bits} = 64 \times 2061 = \mathbf{131,904\text{ bits}} \quad (16,488\text{ bytes} \approx 16.10\text{ KiB})

◇Problem 3: Sizing a 4-Way Set Associative Cache

Problem Statement

A 4-way block set associative cache consists of 64 blocks64\text{ blocks} total (K=4K = 4). Main memory contains 4096 blocks4096\text{ blocks}, each of 128 words128\text{ words}, with 16 bits16\text{ bits} per word.


Step-by-Step Solutions

a. Main Memory Address Width

A=log⁡2(4096×128)=19 bitsA = \log_2(4096 \times 128) = \mathbf{19\text{ bits}}


b. TAG, SET, and WORD Fields

  • Number of Sets:
    S=64 cache blocks4 blocks/set=16 setsS = \frac{64\text{ cache blocks}}{4\text{ blocks/set}} = 16\text{ sets}
  • WORD Offset (w)=log⁡2(128)=7 bits\text{WORD Offset } (w) = \log_2(128) = 7\text{ bits}
  • SET Index (d)=log⁡2(16 sets)=4 bits\text{SET Index } (d) = \log_2(16\text{ sets}) = 4\text{ bits}
  • TAG Field (t)=19−(4+7)=8 bits(log⁡2(409616)=log⁡2(256)=8 bits)\text{TAG Field } (t) = 19 - (4 + 7) = \mathbf{8\text{ bits}} \quad \left(\log_2\left(\frac{4096}{16}\right) = \log_2(256) = 8\text{ bits}\right)

TAG (8 bits)SET INDEX (4 bits)WORD OFFSET (7 bits)Bits [18:11]Bits [10:7]Bits [6:0]\begin{array}{|c|c|c|} \hline \textbf{TAG (8 bits)} & \textbf{SET INDEX (4 bits)} & \textbf{WORD OFFSET (7 bits)} \\ \hline \text{Bits [18:11]} & \text{Bits [10:7]} & \text{Bits [6:0]} \\ \hline \end{array}


c. Mapping of Memory Block 1000

Cache Set=MM Block Number(modTotal Sets)=1000(mod16)=8\text{Cache Set} = \text{MM Block Number} \pmod{\text{Total Sets}} = 1000 \pmod{16} = \mathbf{8}
Memory Block 1000 maps to Cache Set 8 (within any of its 4 lines)\mathbf{\text{Memory Block 1000 maps to Cache Set 8 (within any of its 4 lines)}}


d. Mapping of Memory Address 1000

  • Memory Address 1000  ⟹  MM Block=⌊1000/128⌋=71000 \implies \text{MM Block} = \lfloor 1000/128 \rfloor = 7
  • Target Cache Set:
    Cache Set=7(mod16)=7\text{Cache Set} = 7 \pmod{16} = \mathbf{7}
    Memory Address 1000 maps to Cache Set 7 (within any of its 4 lines)\mathbf{\text{Memory Address 1000 maps to Cache Set 7 (within any of its 4 lines)}}

e. Total Cache Size (including Tag and Valid bits)

  • Bits per cache line:
    Line Bits=2048 data+8 tag+1 valid=2057 bits\text{Line Bits} = 2048\text{ data} + 8\text{ tag} + 1\text{ valid} = 2057\text{ bits}
  • Total cache memory size:
    Total Bits=64×2057=131,648 bits(16,456 bytes≈16.07 KiB)\text{Total Bits} = 64 \times 2057 = \mathbf{131,648\text{ bits}} \quad (16,456\text{ bytes} \approx 16.07\text{ KiB})

Comparative Architecture Summary (64-Block Configurations)

Cache OrganizationTag BitsIndex/Set BitsOffset BitsBits/LineTotal Size (Bits)Tag Overhead (Bits)
Direct-Mapped6666 (Line)7720552055131,520131,520384384
4-Way Set Associative8844 (Set)7720572057131,648131,648512512
Fully Associative1212007720612061131,904131,904768768

◇Problem 4: Byte-Addressable Cache Reference Traces

Problem Statement

A byte-addressable computer has a data cache of 32 bytes32\text{ bytes}. Each cache block is 4 bytes4\text{ bytes}.

  • Number of Cache Blocks: C=32 bytes4 bytes/block=8 blocksC = \frac{32\text{ bytes}}{4\text{ bytes/block}} = 8\text{ blocks}
  • Byte Offset: w=log⁡2(4)=2 bitsw = \log_2(4) = 2\text{ bits}

Sequence of hex byte addresses (12 references12\text{ references}):
Addresses: 200, 204, 208, 20C, 2F4, 2F0, 200, 204, 218, 21C, 24C, 2F4\text{Addresses: } \text{200, 204, 208, 20C, 2F4, 2F0, 200, 204, 218, 21C, 24C, 2F4}


Address Translation Table

For each byte address AA, Block Number B=⌊A/4⌋=A≫2B = \lfloor A / 4 \rfloor = A \gg 2:

StepHex AddressDecimal AddressBinary AddressBlock Number (BB)Direct Line (B(mod8)B \pmod 8)4-Way Set (B(mod2)B \pmod 2)
10x200512...0010 0000 0000128 (0x80)0Set 0
20x204516...0010 0000 0100129 (0x81)1Set 1
30x208520...0010 0000 1000130 (0x82)2Set 0
40x20C524...0010 0000 1100131 (0x83)3Set 1
50x2F4756...0010 1111 0100189 (0xBD)5Set 1
60x2F0752...0010 1111 0000188 (0xBC)4Set 0
70x200512...0010 0000 0000128 (0x80)0Set 0
80x204516...0010 0000 0100129 (0x81)1Set 1
90x218536...0010 0001 1000134 (0x86)6Set 0
100x21C540...0010 0001 1100135 (0x87)7Set 1
110x24C588...0010 0100 1100147 (0x93)3Set 1
120x2F4756...0010 1111 0100189 (0xBD)5Set 1

Trace Evaluations

4a. Direct-Mapped Cache (8 lines L0…L7L_0 \dots L_7)

  • Access 1 (0x200 →\rightarrow Blk 128 →\rightarrow L0L_0): MISS   ⟹  L0=128\implies L_0 = 128 (200-203)
  • Access 2 (0x204 →\rightarrow Blk 129 →\rightarrow L1L_1): MISS   ⟹  L1=129\implies L_1 = 129 (204-207)
  • Access 3 (0x208 →\rightarrow Blk 130 →\rightarrow L2L_2): MISS   ⟹  L2=130\implies L_2 = 130 (208-20B)
  • Access 4 (0x20C →\rightarrow Blk 131 →\rightarrow L3L_3): MISS   ⟹  L3=131\implies L_3 = 131 (20C-20F)
  • Access 5 (0x2F4 →\rightarrow Blk 189 →\rightarrow L5L_5): MISS   ⟹  L5=189\implies L_5 = 189 (2F4-2F7)
  • Access 6 (0x2F0 →\rightarrow Blk 188 →\rightarrow L4L_4): MISS   ⟹  L4=188\implies L_4 = 188 (2F0-2F3)
  • Access 7 (0x200 →\rightarrow Blk 128 →\rightarrow L0L_0): HIT (L0L_0 holds 128)
  • Access 8 (0x204 →\rightarrow Blk 129 →\rightarrow L1L_1): HIT (L1L_1 holds 129)
  • Access 9 (0x218 →\rightarrow Blk 134 →\rightarrow L6L_6): MISS   ⟹  L6=134\implies L_6 = 134 (218-21B)
  • Access 10 (0x21C →\rightarrow Blk 135 →\rightarrow L7L_7): MISS   ⟹  L7=135\implies L_7 = 135 (21C-21F)
  • Access 11 (0x24C →\rightarrow Blk 147 →\rightarrow L3L_3): MISS   ⟹  L3=147\implies L_3 = 147 (24C-24F) (evicts 131)
  • Access 12 (0x2F4 →\rightarrow Blk 189 →\rightarrow L5L_5): HIT (L5L_5 holds 189)

Final Direct-Mapped Cache Contents:

  • L0L_0: Block 128 (0x200 - 0x203)
  • L1L_1: Block 129 (0x204 - 0x207)
  • L2L_2: Block 130 (0x208 - 0x20B)
  • L3L_3: Block 147 (0x24C - 0x24F)
  • L4L_4: Block 188 (0x2F0 - 0x2F3)
  • L5L_5: Block 189 (0x2F4 - 0x2F7)
  • L6L_6: Block 134 (0x218 - 0x21B)
  • L7L_7: Block 135 (0x21C - 0x21F)
  • Total Hits = 3, Total Misses = 9

4b. Fully Associative Cache + LRU (8 slots)

  • Access 1 (0x200, Blk 128): MISS   ⟹  [128]\implies [128]
  • Access 2 (0x204, Blk 129): MISS   ⟹  [129,128]\implies [129, 128]
  • Access 3 (0x208, Blk 130): MISS   ⟹  [130,129,128]\implies [130, 129, 128]
  • Access 4 (0x20C, Blk 131): MISS   ⟹  [131,130,129,128]\implies [131, 130, 129, 128]
  • Access 5 (0x2F4, Blk 189): MISS   ⟹  [189,131,130,129,128]\implies [189, 131, 130, 129, 128]
  • Access 6 (0x2F0, Blk 188): MISS   ⟹  [188,189,131,130,129,128]\implies [188, 189, 131, 130, 129, 128]
  • Access 7 (0x200, Blk 128): HIT   ⟹  [128,188,189,131,130,129]\implies [128, 188, 189, 131, 130, 129]
  • Access 8 (0x204, Blk 129): HIT   ⟹  [129,128,188,189,131,130]\implies [129, 128, 188, 189, 131, 130]
  • Access 9 (0x218, Blk 134): MISS   ⟹  [134,129,128,188,189,131,130]\implies [134, 129, 128, 188, 189, 131, 130]
  • Access 10 (0x21C, Blk 135): MISS   ⟹  [135,134,129,128,188,189,131,130]\implies [135, 134, 129, 128, 188, 189, 131, 130] (Cache full)
  • Access 11 (0x24C, Blk 147): MISS (Evict LRU 130)   ⟹  [147,135,134,129,128,188,189,131]\implies [147, 135, 134, 129, 128, 188, 189, 131]
  • Access 12 (0x2F4, Blk 189): HIT   ⟹  [189,147,135,134,129,128,188,131]\implies [189, 147, 135, 134, 129, 128, 188, 131]

Final Fully Associative LRU Cache Contents:

  • Blocks: {189,147,135,134,129,128,188,131}\{189, 147, 135, 134, 129, 128, 188, 131\} (Addresses 0x2F4, 0x24C, 0x21C, 0x218, 0x204, 0x200, 0x2F0, 0x20C)
  • Total Hits = 3, Total Misses = 9

4c. Fully Associative Cache + MRU (8 slots)

  • Accesses 1–6: Compulsory misses filling slots with Blocks {128,129,130,131,189,188}\{128, 129, 130, 131, 189, 188\}, MRU=188\text{MRU} = 188.
  • Access 7 (0x200, Blk 128): HIT, MRU→128\text{MRU} \rightarrow 128.
  • Access 8 (0x204, Blk 129): HIT, MRU→129\text{MRU} \rightarrow 129.
  • Access 9 (0x218, Blk 134): MISS   ⟹  \implies inserts into slot 7, MRU→134\text{MRU} \rightarrow 134.
  • Access 10 (0x21C, Blk 135): MISS   ⟹  \implies inserts into slot 8 (cache now full), MRU→135\text{MRU} \rightarrow 135.
  • Access 11 (0x24C, Blk 147): MISS   ⟹  \implies evicts MRU (135), loads 147, MRU→147\text{MRU} \rightarrow 147.
  • Access 12 (0x2F4, Blk 189): HIT (189 is in cache), MRU→189\text{MRU} \rightarrow 189.

Final Fully Associative MRU Cache Contents:

  • Blocks: {128,129,130,131,189,188,134,147}\{128, 129, 130, 131, 189, 188, 134, 147\}
  • Total Hits = 3, Total Misses = 9

4d. 4-Way Set Associative Cache + LRU (2 sets: Set 0 and Set 1, 4 blocks/set)

  • Set 0 (Even blocks: 128, 130, 188, 134):
    • Access 1 (128): MISS   ⟹  [128]\implies [128]
    • Access 3 (130): MISS   ⟹  [130,128]\implies [130, 128]
    • Access 6 (188): MISS   ⟹  [188,130,128]\implies [188, 130, 128]
    • Access 7 (128): HIT   ⟹  [128,188,130]\implies [128, 188, 130]
    • Access 9 (134): MISS   ⟹  [134,128,188,130]\implies [134, 128, 188, 130] (Set 0 Full)
  • Set 1 (Odd blocks: 129, 131, 189, 135, 147):
    • Access 2 (129): MISS   ⟹  [129]\implies [129]
    • Access 4 (131): MISS   ⟹  [131,129]\implies [131, 129]
    • Access 5 (189): MISS   ⟹  [189,131,129]\implies [189, 131, 129]
    • Access 8 (129): HIT   ⟹  [129,189,131]\implies [129, 189, 131]
    • Access 10 (135): MISS   ⟹  [135,129,189,131]\implies [135, 129, 189, 131] (Set 1 Full)
    • Access 11 (147): MISS   ⟹  \implies Evicts LRU (131)   ⟹  [147,135,129,189]\implies [147, 135, 129, 189]
    • Access 12 (189): HIT   ⟹  [189,147,135,129]\implies [189, 147, 135, 129]

Final 4-Way Set Associative LRU Cache Contents:

  • Set 0: {134,128,188,130}\{134, 128, 188, 130\} (Hex 0x218, 0x200, 0x2F0, 0x208)
  • Set 1: {189,147,135,129}\{189, 147, 135, 129\} (Hex 0x2F4, 0x24C, 0x21C, 0x204)
  • Total Hits = 3, Total Misses = 9

4e. 4-Way Set Associative Cache + MRU (2 sets, 4 blocks/set)

  • Set 0:
    • Access 1 (128): MISS   ⟹  {128}\implies \{128\}, MRU=128\text{MRU} = 128
    • Access 3 (130): MISS   ⟹  {128,130}\implies \{128, 130\}, MRU=130\text{MRU} = 130
    • Access 6 (188): MISS   ⟹  {128,130,188}\implies \{128, 130, 188\}, MRU=188\text{MRU} = 188
    • Access 7 (128): HIT, MRU=128\text{MRU} = 128
    • Access 9 (134): MISS   ⟹  {128,130,188,134}\implies \{128, 130, 188, 134\}, MRU=134\text{MRU} = 134 (Set 0 Full)
  • Set 1:
    • Access 2 (129): MISS   ⟹  {129}\implies \{129\}, MRU=129\text{MRU} = 129
    • Access 4 (131): MISS   ⟹  {129,131}\implies \{129, 131\}, MRU=131\text{MRU} = 131
    • Access 5 (189): MISS   ⟹  {129,131,189}\implies \{129, 131, 189\}, MRU=189\text{MRU} = 189
    • Access 8 (129): HIT, MRU=129\text{MRU} = 129
    • Access 10 (135): MISS   ⟹  {129,131,189,135}\implies \{129, 131, 189, 135\}, MRU=135\text{MRU} = 135 (Set 1 Full)
    • Access 11 (147): MISS   ⟹  \implies Evicts MRU (135)   ⟹  {129,131,189,147}\implies \{129, 131, 189, 147\}, MRU=147\text{MRU} = 147
    • Access 12 (189): HIT, MRU=189\text{MRU} = 189

Final 4-Way Set Associative MRU Cache Contents:

  • Set 0: {128,130,188,134}\{128, 130, 188, 134\}
  • Set 1: {129,131,189,147}\{129, 131, 189, 147\}
  • Total Hits = 3, Total Misses = 9

◇Problem 5: Non-Load-Through Read Policy Benchmark

Problem Statement

Given:

  • Cache Capacity = 4 cache blocks4\text{ cache blocks}
  • Block Size = 4 words/block4\text{ words/block}
  • Associativity: 2 blocks/set2\text{ blocks/set} (for set associative   ⟹  2 sets\implies 2\text{ sets})
  • tcache=1 nst_{\text{cache}} = 1\text{ ns}, tmem=10 nst_{\text{mem}} = 10\text{ ns}
  • Non-load-through read policy:
    • thit=1 nst_{\text{hit}} = 1\text{ ns}
    • tmiss=1 ns+10 ns=11 nst_{\text{miss}} = 1\text{ ns} + 10\text{ ns} = 11\text{ ns}
  • Main Memory Block Sequence:
    Sequence: 1,2,3,4,5,4,6,3(N=8 accesses)\text{Sequence: } 1, 2, 3, 4, 5, 4, 6, 3 \quad (N = 8\text{ accesses})

Step-by-Step Derivations for all 5 Configurations

1. Direct Mapping (Line=B(mod4)\text{Line} = B \pmod 4)

  • Access 1 (B=1→L1B=1 \rightarrow L_1): MISS   ⟹  L1=1\implies L_1 = 1
  • Access 2 (B=2→L2B=2 \rightarrow L_2): MISS   ⟹  L2=2\implies L_2 = 2
  • Access 3 (B=3→L3B=3 \rightarrow L_3): MISS   ⟹  L3=3\implies L_3 = 3
  • Access 4 (B=4→L0B=4 \rightarrow L_0): MISS   ⟹  L0=4\implies L_0 = 4
  • Access 5 (B=5→L1B=5 \rightarrow L_1): MISS (Evicts 1)   ⟹  L1=5\implies L_1 = 5
  • Access 6 (B=4→L0B=4 \rightarrow L_0): HIT (L0L_0 holds 4)
  • Access 7 (B=6→L2B=6 \rightarrow L_2): MISS (Evicts 2)   ⟹  L2=6\implies L_2 = 6
  • Access 8 (B=3→L3B=3 \rightarrow L_3): HIT (L3L_3 holds 3)

Metrics:

  • Hits = 22, Misses = 66
  • Hit Rate = 28=25.00%\frac{2}{8} = \mathbf{25.00\%}, Miss Rate = 68=75.00%\frac{6}{8} = \mathbf{75.00\%}
  • Total Memory Access Time:
    Ttotal=(2×1 ns)+(6×11 ns)=2+66=68 nsT_{\text{total}} = (2 \times 1\text{ ns}) + (6 \times 11\text{ ns}) = 2 + 66 = \mathbf{68\text{ ns}}
  • Average Memory Access Time:
    AMAT=68 ns8=8.50 ns\text{AMAT} = \frac{68\text{ ns}}{8} = \mathbf{8.50\text{ ns}}
  • Final Cache: [L0:4,L1:5,L2:6,L3:3][L_0: 4, L_1: 5, L_2: 6, L_3: 3]

2. Fully Associative Mapping (LRU)

  • Access 1 (1): MISS   ⟹  [1]\implies [1]
  • Access 2 (2): MISS   ⟹  [2,1]\implies [2, 1]
  • Access 3 (3): MISS   ⟹  [3,2,1]\implies [3, 2, 1]
  • Access 4 (4): MISS   ⟹  [4,3,2,1]\implies [4, 3, 2, 1] (Full)
  • Access 5 (5): MISS   ⟹  \implies Evict LRU (1)   ⟹  [5,4,3,2]\implies [5, 4, 3, 2]
  • Access 6 (4): HIT   ⟹  \implies Promote 4   ⟹  [4,5,3,2]\implies [4, 5, 3, 2]
  • Access 7 (6): MISS   ⟹  \implies Evict LRU (2)   ⟹  [6,4,5,3]\implies [6, 4, 5, 3]
  • Access 8 (3): HIT   ⟹  \implies Promote 3   ⟹  [3,6,4,5]\implies [3, 6, 4, 5]

Metrics:

  • Hits = 22, Misses = 66
  • Hit Rate = 25.00%\mathbf{25.00\%}, Miss Rate = 75.00%\mathbf{75.00\%}
  • Total Access Time: Ttotal=68 nsT_{\text{total}} = \mathbf{68\text{ ns}}, AMAT=8.50 ns\text{AMAT} = \mathbf{8.50\text{ ns}}
  • Final Cache: {3,6,4,5}\{3, 6, 4, 5\}

3. Fully Associative Mapping (MRU)

  • Access 1 (1): MISS   ⟹  {1}\implies \{1\}, MRU=1\text{MRU} = 1
  • Access 2 (2): MISS   ⟹  {1,2}\implies \{1, 2\}, MRU=2\text{MRU} = 2
  • Access 3 (3): MISS   ⟹  {1,2,3}\implies \{1, 2, 3\}, MRU=3\text{MRU} = 3
  • Access 4 (4): MISS   ⟹  {1,2,3,4}\implies \{1, 2, 3, 4\}, MRU=4\text{MRU} = 4 (Full)
  • Access 5 (5): MISS   ⟹  \implies Evict MRU (4)   ⟹  {1,2,3,5}\implies \{1, 2, 3, 5\}, MRU=5\text{MRU} = 5
  • Access 6 (4): MISS   ⟹  \implies Evict MRU (5)   ⟹  {1,2,3,4}\implies \{1, 2, 3, 4\}, MRU=4\text{MRU} = 4
  • Access 7 (6): MISS   ⟹  \implies Evict MRU (4)   ⟹  {1,2,3,6}\implies \{1, 2, 3, 6\}, MRU=6\text{MRU} = 6
  • Access 8 (3): HIT (3 in cache)   ⟹  {1,2,3,6}\implies \{1, 2, 3, 6\}, MRU=3\text{MRU} = 3

Metrics:

  • Hits = 11, Misses = 77
  • Hit Rate = 18=12.50%\frac{1}{8} = \mathbf{12.50\%}, Miss Rate = 78=87.50%\frac{7}{8} = \mathbf{87.50\%}
  • Total Access Time:
    Ttotal=(1×1 ns)+(7×11 ns)=1+77=78 nsT_{\text{total}} = (1 \times 1\text{ ns}) + (7 \times 11\text{ ns}) = 1 + 77 = \mathbf{78\text{ ns}}
  • Average Memory Access Time:
    AMAT=78 ns8=9.75 ns\text{AMAT} = \frac{78\text{ ns}}{8} = \mathbf{9.75\text{ ns}}
  • Final Cache: {1,2,3,6}\{1, 2, 3, 6\}

4. Block Set Associative (LRU, 2 sets)

  • Set 0 (Even: 2, 4, 6), Set 1 (Odd: 1, 3, 5)
  • Access 1 (B=1→S1B=1 \rightarrow S_1): MISS   ⟹  S1:[1]\implies S_1: [1]
  • Access 2 (B=2→S0B=2 \rightarrow S_0): MISS   ⟹  S0:[2]\implies S_0: [2]
  • Access 3 (B=3→S1B=3 \rightarrow S_1): MISS   ⟹  S1:[3,1]\implies S_1: [3, 1] (Full)
  • Access 4 (B=4→S0B=4 \rightarrow S_0): MISS   ⟹  S0:[4,2]\implies S_0: [4, 2] (Full)
  • Access 5 (B=5→S1B=5 \rightarrow S_1): MISS   ⟹  \implies Evict LRU (1)   ⟹  S1:[5,3]\implies S_1: [5, 3]
  • Access 6 (B=4→S0B=4 \rightarrow S_0): HIT   ⟹  S0:[4,2]\implies S_0: [4, 2]
  • Access 7 (B=6→S0B=6 \rightarrow S_0): MISS   ⟹  \implies Evict LRU (2)   ⟹  S0:[6,4]\implies S_0: [6, 4]
  • Access 8 (B=3→S1B=3 \rightarrow S_1): HIT   ⟹  S1:[3,5]\implies S_1: [3, 5]

Metrics:

  • Hits = 22, Misses = 66
  • Hit Rate = 25.00%\mathbf{25.00\%}, Miss Rate = 75.00%\mathbf{75.00\%}
  • Total Access Time: Ttotal=68 nsT_{\text{total}} = \mathbf{68\text{ ns}}, AMAT=8.50 ns\text{AMAT} = \mathbf{8.50\text{ ns}}
  • Final Cache: Set 0 = {6,4}\{6, 4\}, Set 1 = {3,5}\{3, 5\}

5. Block Set Associative (MRU, 2 sets)

  • Access 1 (B=1→S1B=1 \rightarrow S_1): MISS   ⟹  S1:{1}\implies S_1: \{1\}, MRU=1\text{MRU} = 1
  • Access 2 (B=2→S0B=2 \rightarrow S_0): MISS   ⟹  S0:{2}\implies S_0: \{2\}, MRU=2\text{MRU} = 2
  • Access 3 (B=3→S1B=3 \rightarrow S_1): MISS   ⟹  S1:{1,3}\implies S_1: \{1, 3\}, MRU=3\text{MRU} = 3
  • Access 4 (B=4→S0B=4 \rightarrow S_0): MISS   ⟹  S0:{2,4}\implies S_0: \{2, 4\}, MRU=4\text{MRU} = 4
  • Access 5 (B=5→S1B=5 \rightarrow S_1): MISS   ⟹  \implies Evict MRU (3)   ⟹  S1:{1,5}\implies S_1: \{1, 5\}, MRU=5\text{MRU} = 5
  • Access 6 (B=4→S0B=4 \rightarrow S_0): HIT   ⟹  S0:{2,4}\implies S_0: \{2, 4\}, MRU=4\text{MRU} = 4
  • Access 7 (B=6→S0B=6 \rightarrow S_0): MISS   ⟹  \implies Evict MRU (4)   ⟹  S0:{2,6}\implies S_0: \{2, 6\}, MRU=6\text{MRU} = 6
  • Access 8 (B=3→S1B=3 \rightarrow S_1): MISS (3 was evicted)   ⟹  \implies Evict MRU (5)   ⟹  S1:{1,3}\implies S_1: \{1, 3\}, MRU=3\text{MRU} = 3

Metrics:

  • Hits = 11, Misses = 77
  • Hit Rate = 18=12.50%\frac{1}{8} = \mathbf{12.50\%}, Miss Rate = 78=87.50%\frac{7}{8} = \mathbf{87.50\%}
  • Total Access Time:
    Ttotal=(1×1 ns)+(7×11 ns)=78 nsT_{\text{total}} = (1 \times 1\text{ ns}) + (7 \times 11\text{ ns}) = \mathbf{78\text{ ns}}
  • Average Memory Access Time:
    AMAT=78 ns8=9.75 ns\text{AMAT} = \frac{78\text{ ns}}{8} = \mathbf{9.75\text{ ns}}
  • Final Cache: Set 0 = {2,6}\{2, 6\}, Set 1 = {1,3}\{1, 3\}

Master Comparison Table for Problem 5

Mapping & Replacement PolicyHitsMissesHit RateMiss RateTotal Access TimeAMATFinal Cache State
1. Direct Mapping2625.00%25.00\%75.00%75.00\%68 ns68\text{ ns}8.50 ns8.50\text{ ns}[4,5,6,3][4, 5, 6, 3]
2. Full Associative (LRU)2625.00%25.00\%75.00%75.00\%68 ns68\text{ ns}8.50 ns8.50\text{ ns}{3,6,4,5}\{3, 6, 4, 5\}
3. Full Associative (MRU)1712.50%12.50\%87.50%87.50\%78 ns78\text{ ns}9.75 ns9.75\text{ ns}{1,2,3,6}\{1, 2, 3, 6\}
4. Set Associative (LRU)2625.00%25.00\%75.00%75.00\%68 ns68\text{ ns}8.50 ns8.50\text{ ns}S0:{6,4},S1:{3,5}S_0:\{6, 4\}, S_1:\{3, 5\}
5. Set Associative (MRU)1712.50%12.50\%87.50%87.50\%78 ns78\text{ ns}9.75 ns9.75\text{ ns}S0:{2,6},S1:{1,3}S_0:\{2, 6\}, S_1:\{1, 3\}

◇Key Architectural Takeaways

  1. Mapping Trade-offs:

    • Direct Mapping offers minimal hardware complexity (1 comparator1\text{ comparator}) and fastest hit time, but suffers from conflict misses when multiple active blocks map to the same line index.
    • Fully Associative Mapping eliminates conflict misses entirely, maximizing hit rate for small caches, but requires C comparatorsC\text{ comparators} operating in parallel, introducing area and power overheads.
    • Set Associative Mapping provides an optimal engineering compromise, capturing most of the hit rate benefit of full associativity with K comparatorsK\text{ comparators} per set.
  2. Replacement Policy Impact:

    • LRU aligns naturally with the principle of temporal locality, preserving recently used blocks.
    • MRU is generally disadvantageous for typical sequential or looping workloads, but is useful in specific scan-resistant access patterns where large datasets exceed cache capacity.
  3. Overhead Calculations:

    • Tag storage constitutes a significant percentage of total on-chip SRAM area. As block size increases, tag overhead per data bit decreases because fewer lines are required to cover the same data capacity.

◇References & Navigation